<?php
/**
 * +----------------------------------------------------------------------
 * | Author: 罗极
 * +----------------------------------------------------------------------
 * | Description: NotFoundResponse.php
 * +----------------------------------------------------------------------
 * | User: Administrator Date: 8/21/ 0021 Time: 14:51
 * +----------------------------------------------------------------------
 */

namespace Framework\Response;

use Framework\Response\Abstracts\ResponseAbstracts;

class NotFoundResponse extends ResponseAbstracts
{
    protected $htmlPath;
    protected $defaultHtml = "<h1 align='center'>404 NotFound</h1><hr /><div align='center'>{[Apache|nginx] ver:[xx.xx]}</div>";

    public function __construct(string $htmlPath) // todo 替换成 View 类型
    {
        $this->htmlPath = $htmlPath;

        if(file_exists($htmlPath)) {
            ob_start();
            include $htmlPath;
            $this->msg = ob_get_contents();
            ob_end_clean();
        } else {
            $this->msg = $this->defaultHtml;
        }

        $this->code = 404;
    }

    public function response()
    {
        $this->sendCode();
        $this->sendMsg($this->msg);
    }
}